/*
========================================================================
 Name        : Mp3Player.cpp
 Author      : 
 Copyright   : Your copyright notice
 Description : 
========================================================================
*/
#include "GameAudioPlayer.h"

_LIT( KAudioFile, "c:\\data\\sounds\\up.wav");

CGameAudioPlayer::CGameAudioPlayer(): iPlayer( NULL )
	{
	iState = (TInt)ENotReady;
	}

void CGameAudioPlayer::ConstructL()
	{
	iPlayer = CMdaAudioPlayerUtility::NewFilePlayerL( KAudioFile, *this );
	iPlayer->SetPriority( EMdaPriorityMax, EMdaPriorityPreferenceTime );
	}

CGameAudioPlayer::~CGameAudioPlayer()
	{
	if( iPlayer )
		{
		iPlayer->Stop();
		iPlayer->Close();
		}
	delete iPlayer;
	iPlayer = NULL;
	}

CGameAudioPlayer* CGameAudioPlayer::NewL()
	{
	CGameAudioPlayer* self = new (ELeave)CGameAudioPlayer;
	CleanupStack::PushL( self );
	self->ConstructL();
	CleanupStack::Pop();
	return self;
	}

void CGameAudioPlayer::MapcInitComplete(TInt aError, 
		const TTimeIntervalMicroSeconds& /*aDuration*/)
	{
	User::LeaveIfError( aError );
	iState = (TInt)EReady;
	}

void CGameAudioPlayer::MapcPlayComplete( TInt aError )
	{
	User::LeaveIfError( aError );
	iPlayer->Stop();
	iState = (TInt)EReady;
	}

void CGameAudioPlayer::Play()
	{
	if( iState == (TInt)EReady )
		{
		iState  = (TInt)EPlaying;
		iPlayer->Play();
		}
	}

void CGameAudioPlayer::GameChanged( CEngine* /*aGame*/ )
    {
    
    }

void CGameAudioPlayer::GamePaused( CEngine* /*aGame*/ )
    {
    
    }

void CGameAudioPlayer::GameOver( CEngine* /*aGame*/ )
    {
    
    }

void CGameAudioPlayer::BallHitsLine( CEngine* /*aGame*/ )
    {
    Play();
    }
